﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;
using log4net.Config;

namespace EggTimerWithStatus
{
    class Logger
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Logger));
        private static Logger instance = null;
        private static bool isConfigured = false;
        static readonly object padlock = new object(); // simple threading lock object

        // ctor to hide singleton
        Logger() { }

        // destructor to clean up
        ~Logger() 
        {
           
        }

        public static Logger Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new Logger();
                    }
                    return instance;
                }
            }
        }

        public static bool IsConfigured { get; set; }
        
        // not what I'm looking for
        public ILog Log 
        {
            get {return log;} 
        }

        public static void Configure(string strLogPath)
        {
            if (strLogPath.Equals(string.Empty))
            {
                BasicConfigurator.Configure();
                IsConfigured = true;
            }
            else
            {
                //
                System.IO.FileInfo logFileInfo = new System.IO.FileInfo(strLogPath);
                if (logFileInfo.Exists)
                {
                    XmlConfigurator.Configure(new System.IO.FileInfo(strLogPath));
                    IsConfigured = true;
                }
                else
                {
                    BasicConfigurator.Configure();
                    IsConfigured = true;
                }
            }

            log.Info("Logger configured.");
        }
    }
}
